/**
 * @description 地图编辑器
 * @author mirahs
 * @email 2892727493@qq.com
 */
import AppConstants from "../../framework/scripts/AppConstants"
import PanelBase from "../../framework/scripts/view/PanelBase"


export default class PanelChoiceDraw extends PanelBase {
    public bundleName: string = 'null'
    public skinPath: string = '_panels/PanelChoiceDraw'
    public panelMaskStyle: number = AppConstants.panelMaskStyle.NoThrough | AppConstants.panelMaskStyle.Black


    protected onInitDone(): void {
        const prefab = this.skin.getChildByName('items').children[0]

        const gridPrefabs = this._args[0] as string[][]

        for (let i = 0; i < gridPrefabs.length; i++) {
            const val = gridPrefabs[i]
            const name = val[0]
            const color = val[1]

            const item = cc.instantiate(prefab)
            item.name = name
            item.color = new cc.Color().fromHEX(color)
            item.opacity = Number(val[2] ?? '255')
            item.children[0].getComponent(cc.Label).string = name

            item.parent = prefab.parent

            item.on(cc.Node.EventType.TOUCH_START, () => {
                this._args[1](i)
                this.close()
            })
        }

        prefab.destroy()
    }
}
